Skip to content

Arshdeep225615024/feature/shift matching system#385

Open
Arshdeep225615024 wants to merge 3 commits into
mainfrom
Arshdeep225615024/feature/shift-matching-system
Open

Arshdeep225615024/feature/shift matching system#385
Arshdeep225615024 wants to merge 3 commits into
mainfrom
Arshdeep225615024/feature/shift-matching-system

Conversation

@Arshdeep225615024
Copy link
Copy Markdown
Collaborator

Shift Matching and Invitation System

Overview

This pull request introduces a new intelligent Shift Matching and Invitation System for the SecureShift backend. The feature allows employers to generate ranked guard recommendations for shifts and invite suitable guards through a structured workflow.

The implementation was designed with minimal disruption to the existing shift lifecycle and assignment system.


Features Implemented

Intelligent Shift Matching

Added a new endpoint:

GET /api/v1/shift-matches/:shiftId

The system generates ranked guard recommendations based on:

  • Guard availability
  • Shift conflict detection
  • Verified licence status
  • Employer favourite guards
  • Same suburb/location matching

Suitability Ranking

Replaced simple boolean suitability with ranking levels:

  • VERY_HIGH
  • HIGH
  • MEDIUM
  • LOW
  • VERY_LOW

Each guard recommendation also includes:

  • Numeric score
  • Matching reasons/explanations

Conflict Detection

Implemented overlapping shift conflict detection.

The system now identifies:

  • Time overlaps
  • Existing assigned/applied shifts
  • Guard scheduling conflicts

Conflicting guards receive reduced scores.


Guard Preference System

Added a new GuardPreference model.

Guards can store:

  • Preferred shift types
  • Preferred fields
  • Preferred suburbs
  • Minimum pay rate
  • Urgent shift preference

Endpoints added:

  • GET /api/v1/shift-matches/preferences/me
  • POST /api/v1/shift-matches/preferences/me

Shift Invitation System

Added a new ShiftInvitation model.

Employers can invite guards directly from match results.

Endpoint added:

  • POST /api/v1/shift-matches/:shiftId/invite/:guardId

Invitation Management

Guards can:

  • View invitations
  • Accept or decline invitations

Endpoints added:

  • GET /api/v1/shift-matches/invitations/me
  • PATCH /api/v1/shift-matches/invitations/:invitationId/respond

Role-Based Access Control (RBAC)

Added security restrictions:

  • Only employers/admins can generate matches
  • Only employers/admins can invite guards
  • Only guards can respond to invitations
  • Guards can only respond to their own invitations

Swagger Documentation

All new functionality has been documented under:

  • Shift Matching

Swagger documentation includes:

  • Matching endpoints
  • Preferences endpoints
  • Invitation endpoints
  • Invitation response endpoints

Workflow

Employer creates shift
→ System generates ranked guard matches
→ Employer invites selected guard
→ Guard views invitation
→ Guard accepts/declines invitation


Future Enhancements

Planned future improvements include:

  • Automatic shift assignment after invitation acceptance
  • Urgent shift mode for last-minute staffing
  • Guard-side recommended open shifts

Notes

This implementation was intentionally designed to avoid major modifications to the existing shift creation, application, and assignment workflow, ensuring compatibility with the current backend architecture.

@Arshdeep225615024
Copy link
Copy Markdown
Collaborator Author

Screenshot 2026-05-15 at 3 24 27 AM Screenshot 2026-05-15 at 3 24 58 AM Screenshot 2026-05-15 at 3 25 45 AM Screenshot 2026-05-15 at 3 25 59 AM Screenshot 2026-05-15 at 3 27 46 AM Screenshot 2026-05-15 at 3 28 00 AM

@uppalkrish
Copy link
Copy Markdown
Collaborator

is this endpoint part of exsisting shift system or will it be a seperate section?

{ id: user._id, role: user.role },
process.env.JWT_SECRET,
{ expiresIn: '1h' }
{ expiresIn: '12h' }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you increase the token expiry
@neethuchandhavarkar are you fine with this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I increased the token expiry for testing purposes, as it was not feasible to create multiple employers and guards, and log back in every hour from postman. We can revert it back now, no problem

return rangeA.start < rangeB.end && rangeB.start < rangeA.end;
};

const getSuitabilityLevel = (score) => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is your logic for score?
we already do have a guard rating system, are you using that? or created something

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

he scoring system is a lightweight recommendation layer built on top of the existing guard data and workflows. It does not replace the existing guard rating system.

The current score combines multiple operational factors including:

availability match
live availability status
conflicting shifts
verified licence status
employer favourites
same suburb/location match
existing guard rating

The existing guard rating is already included as one component of the overall suitability score. The intention was to create a broader staffing suitability recommendation rather than relying only on review ratings.

@Arshdeep225615024
Copy link
Copy Markdown
Collaborator Author

is this endpoint part of exsisting shift system or will it be a seperate section?

For now this shift matching system acts as a recommendation system for employers to get most suitable guards for their shifts , It was intentionally made to not change the current shift matching system, but It can be definitely be extended as a complete shift matching system by future students as I have also included the invitation feature (from employer to guards)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants